<template>

  <el-dialog :close-on-click-modal="false" destroy-on-close :show-close="false" width="30%" v-model="LIZHISTATUS" title="申请离职">
    <!-- <el-form :model="formData" :rules="formRules" size="small" :inline="false" label-width="100px">
      <el-form-item label="主题" prop="title">
        <el-input v-model="formData.title" placeholder="请填写主题" maxlength="32" size="small"/>
      </el-form-item>
      <el-form-item label="员工" prop="staffId">
        <el-select v-model="formData.staffId" placeholder="请选择员工" size="small" filterable>
          <el-option v-for="item in staffList" :key="item.id" :value="item.id" :label="item.name"/>
        </el-select>
      </el-form-item>
      <el-form-item label="计划离职日期" prop="occurDate">
        <el-date-picker value-format="YYYY-MM-DD hh:mm:ss" v-model="formData.occurDate" type="datetime" placeholder="请选择计划离职日期" size="small"/>
      </el-form-item>
      <el-form-item label="薪资结算日期" prop="settlementDate">
        <el-date-picker value-format="YYYY-MM-DD hh:mm:ss" v-model="formData.settlementDate" type="datetime" placeholder="请选择薪资结算日期" size="small"/>
      </el-form-item>
      <el-form-item label="离职类型" prop="staffLeaveType">
        <el-select v-model="formData.staffLeaveType" placeholder="请选择离职类型" size="small">
          <el-option v-for="item in dictMap['LeaveOfficeType']" :key="item.value" :value="item.value" :label="item.name"/>
        </el-select>
      </el-form-item>
      <el-form-item label="离职原因" prop="content">
        <editor v-model="formData.content"/>
      </el-form-item>
      <el-form-item label="优先度" prop="priority">
        <el-radio-group v-model="formData.priority" size="small">
          <el-radio :label="0" size="small">普通</el-radio>
          <el-radio :label="1" size="small">高</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注信息" prop="remark">
        <el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请填写备注信息" size="small"/>
      </el-form-item>
    </el-form> -->
    <dimission-apply-form ref="form"></dimission-apply-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button size="large" @click="close">取消</el-button>
        <el-button @click="submit" type="primary" size="large">确认</el-button>
      </div>
    </template>
  </el-dialog>

</template>

<script>
// 离职申请 
import {onMounted, reactive, toRefs, ref} from 'vue'
import {listByState} from '/@/api/oa/staff'
import {getDictByCodes} from '/@/api/sys/dict'
import {homeApi} from '/@/api/home/index'
import {format} from '/@/views/home/component/lib/utils'
import Editor from '/@/components/editor/index.vue'
import DimissionApplyForm from '/@/views/matter/components/DimissionApplyForm.vue'

const homeCalendar = homeApi()
export default {
  name: 'DimissionApply',
  components: {
    Editor,
    DimissionApplyForm
  },
  props: {
    LIZHISTATUS: {
      type: Boolean,
      default: false
    },
    idw: {
      type: String,
      default: ''
    }
  },
  emits: ['LiZhiFormClose'],
  setup(props, context) {
    const form = ref(null)
    const state = reactive({
      // formData: {
      //   title: '离职申请',
      //   staffId: null,
      //   content: null,    // 离职原因
      //   occurDate: null,    // 离职申请时间
      //   settlementDate: null,   // 薪资结算时间
      //   staffLeaveType: null,   // 离职类型
      //   remark: null,   // 备注信息
      //   state: 2,           // 状态 -1草稿 0未开始 1进行中 2已完成 3已退回  4已取消 5已撤回
      //   priority: 0        // 优先级 0普通 1重要
      // },
      // formRules: {
      //   title: {required: true, message: '请填写主题', trigger: 'blur'},
      //   staffId: {required: true, message: '请选择员工', trigger: 'change'},
      //   content: {required: true, message: '请填写离职原因', trigger: 'blur'},
      //   occurDate: {required: true, message: '请选择离职申请日期', trigger: 'change'},
      //   settlementDate: {required: true, message: '请选择薪资结算时间', trigger: 'change'},
      //   staffLeaveType: {required: true, message: '请选择离职类型', trigger: 'change'}
      // },
      // dictMap: {},
      // staffList: [],
      outerVisible: true
    })
    let close = () => {
      context.emit('LiZhiFormClose')
      form.value.reset()
      // state.formData = {
      //   title: '离职申请',
      //   staffId: null,
      //   content: null,    // 离职原因
      //   occurDate: null,    // 离职申请时间
      //   settlementDate: null,   // 薪资结算时间
      //   staffLeaveType: null,   // 离职类型
      //   remark: null,   // 备注信息
      //   state: 2,           // 状态 -1草稿 0未开始 1进行中 2已完成 3已退回  4已取消 5已撤回
      //   priority: 0        // 优先级 0普通 1重要
      // }
    }
    let submit = () => {
      form.value.submit()
      // state.formData.occurDate = format(state.occurDate, 'yyyy-MM-dd HH:mm')
      // state.formData.settlementDate = format(state.settlementDate, 'yyyy-MM-dd HH:mm')
      // console.log(state.formData)
      // homeCalendar
      //     .modifyMatter(state.formData)
      //     .then((res) => {
      //       if (res.code === 1) {

      //       }
      //     })
    }
    const getStaffData = async () => {
      try {
        const res = await listByState('')
        state.staffList = res.data
      } catch (e) {
        console.log(e)
      }
    }
    onMounted(() => {
      getDictByCodes(['LeaveOfficeType']).then(res => {
        state.dictMap = res.data
      }).catch(e => console.log(e))
      getStaffData()
      console.log(form.value)
    })

    return {
      ...toRefs(state),
      getStaffData,
      close,
      submit
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
